package com.qdu.hyy.MovieHighestRating;

import com.qdu.hyy.MovieWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//JOB2  end!

public class MovieHighestRatingMapper extends Mapper<LongWritable, Text, Text, DoubleWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {


        String[] fields = value.toString().split(",");

        if (fields.length != 22) {
            return;
        }
        if (fields[0].equals("id"))
        {
            return;
        }


            // 创建一个新的 MovieWritable 对象
        if ((fields[12] != null && !(fields[12].isEmpty()))) {
            Double rating = Double.parseDouble(fields[12]);
            context.write(new Text(fields[1]), new DoubleWritable(rating));
            //System.out.println(new Text(fields[1])+"   "+new DoubleWritable(rating));
            // ... 其余的代码
        } else {
            // 处理空字符串的情况，比如记录一个警告或跳过该记录
        }



    }


}
